package ExeptionTest;

import com.sun.istack.internal.SAXException2;
import com.sun.xml.internal.bind.v2.runtime.output.StAXExStreamWriterOutput;

import java.util.InputMismatchException;
import java.util.Scanner;

public class TryDemoOne {

        public static void main(String[] args){

          /*  int one = 12;
            int two = 2;
            System.out.println("商为："+(one/two));
          */

            Scanner input = new Scanner(System.in);

            System.out.println("输入整数:");
            try {
                int one = input.nextInt();
                int two = input.nextInt();
                System.out.println("商为："+(one/two));
            }
            catch(ArithmeticException e){
                System.exit(1);//终止程序运行/终止当前运行的java虚拟机，无条件终止运行
                e.printStackTrace();//打印出错误的堆栈信息，堆栈信息出现位置相对随机
                System.out.println("除数不能为零");
            }
            catch(InputMismatchException e){
                e.printStackTrace();
                System.out.println("输入格式错误");
            }
            catch(Exception e){
                System.out.println("程序出错了");
            }
            finally {
                System.out.println("~结束~");
            }

        }
}
